package com.example.job.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.job.po.SysJob;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * @author chentao
 * @version 1.0
 * @description: TODO
 * @date 2025/3/26 下午11:03
 */
@Mapper
public interface SysJobMapper extends BaseMapper<SysJob> {

    @Select("select * from sys_job where status = 1 and (next_run_time <= #{runTime} or next_run_time is null) order by next_run_time asc")
    public List<SysJob> selectJobList(@Param("runTime") Date runTime);

    @Select("select * from sys_job where status = 1 and next_run_time > #{runTime} order by next_run_time asc")
    public List<SysJob> selectJobListBeyondRunTime(@Param("runTime") Date runTime);

    @Select("select min(next_run_time) from sys_job where next_run_time > #{runTime}")
    public Date selectNextRunTime(@Param("runTime") Date runTime);
}
